\documentclass[12pt]{article}
\usepackage{times}
\usepackage{graphicx}
\usepackage{sidecap}
\usepackage{wrapfig}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\baselinestretch}{1.2}
\newenvironment{mylisting}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting2}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}

%%% This file is Open Content

\begin{document}
	\textbf{{\Huge Bloodlands}}
{\center{Dec 29, 2011, 
	Johan Ceuppens, Theo D'Hondt - Vrije Universiteit Brussel}}
\\
{\large{\textbf{\center Abstract}}}
\\
\\
\section{\large Introduction}



\begin{mylisting}
\begin{verbatim}

	
package games;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.event.*;

public class Bloodlands2 extends Frame implements KeyListener
{

static private int DX = 3;
static private int DY = 3;
//private static Frame f = new Frame("Butterfly");
private static java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
private static ImageCanvas imageCanvas = new ImageCanvas("./mapfile.1", 50,37);
private static Player player = new Player();
private static Room room;

public void init() {
  this.addKeyListener(this);
}

public Bloodlands2()
{

  init();
  imageCanvas.setSize(800,600);
  add(imageCanvas);//, BorderLayout.LEFT);
  pack();
  setSize(800,600);
  
  /*new KeyListener() 
   {
   
   }*/
  
  
  room = new Room1(50,37,"./mapfile.1");
  imageCanvas.setRoomData(room);
  
  int n = 1;
  int j = 0;
  //this.show();
  try {
    while (true) {
     
      //repaint();
      Thread.sleep(300);
    }
  } catch (Exception e)
  {
    System.out.println("excepted Bloodlands2.java");
  }
}

public final static void main(String[] args)
{

  new Bloodlands2();
  
//NOTE final

}

public void keyPressed(KeyEvent e) {                                  
   //System.out.println("foo="+e.getKeyChar());
 
 if (e.getKeyChar() == 'j') {
  imageCanvas.addToX(DX);
  //this.show();
  repaint();
 }  
 if (e.getKeyChar() == 'l') {
  imageCanvas.addToX(-DX);
  //this.show();
  repaint();
 }  
 if (e.getKeyChar() == 's') {
  player.notifySword();//drawWithSword(imageCanvas);
  //this.show();
  repaint();
 }
/* if (e.getKeyChar() == 'i') {
  enemies[0].addToY(DY);
  imageCanvas.addToY(DY);
  f.show();
 }  
 if (e.getKeyChar() == 'k') {
  enemies[0].addToY(-DY);
  imageCanvas.addToY(-DY);
  f.show();
 }  
*/
}
public void keyReleased(KeyEvent e) {                                  
//   System.out.print("bar="); 
}
public void keyTyped(KeyEvent e) {                                  
//   System.out.print("baz="); 
}
public void actionPerformed(ActionEvent e) {                                  
//   System.out.println("foo"); 
}
public void paint(Graphics g) {
  //super.paint(g);
  System.out.println("bar");
  //while (true) 
//{
// if (!imageCanvas.collide(player)) {
//  imageCanvas.addToY(-1);
// }
  imageCanvas.paint(g); 
 //room.draw(imageCanvas);
 player.draw(imageCanvas);
 
 for (int i = 0; i < 100; i++)
 {
  Enemy e = imageCanvas.enemies.vectorRef(i);

  if (e == null)
   continue;
  e.update();
  if (e.collide(player, imageCanvas)) {
   if (e.hit()) imageCanvas.enemies.vectorSet(i, null); 
  }
  imageCanvas.drawEnemy(e);
  
  
  //e.draw(imageCanvas);
 }//
 //if (j++ % 1000000 == 0) { f.show(); j = 0; }

 if (room.changeRoom(imageCanvas) != null)
 {
  room = room.changeRoom(imageCanvas);
   //System.out.println("Changed room");
 }

// this.show();


 
//  //g.drawImage(bgimage, getX(), getY(), this); 
//  //g.drawImage(roombgimage, getX(), getY(), this);
}


};
package games;

import java.awt.*;
import java.awt.event.*;

public class Bullfrog extends Enemy
{
java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
Bullfrog(int xx, int yy)
{
super(null,xx,yy, 20, 36,36);
super.image = toolkit.getImage("./pics/oneeye1-36x36.png");
}
public boolean hit()
{

hitpoints -= 1;
if (hitpoints < 0)
	return true;
else
	return false;
}

void drawEnemy(ImageCanvas ic)
{
    ic.paintEnemy(this);
}
public void update()
{
x -=0.000004;


}

};
package games;
import javax.swing.*;
import java.awt.*;
import java.applet.*;

public class Canvas1 extends Canvas
{
public Canvas1() {
	setBackground(Color.yellow);
	setSize(800,600);
}

public void paint(Graphics g)
{
Graphics2D g2;
int h;

g2 = (Graphics2D) g;
h = getHeight();
//g2.drawString("Druid");

g.drawRect(0,0,200,200);

//Image img = getImage(getCodeBase(), "./pics/jewel.jpg");
//Image img = getImage("./pics/jewel.jpg");
//if (img != null)                                                          
//      g.drawImage(img, 0, 0, this);
}


};
package games;

import java.util.*;
import java.awt.*;
import java.awt.event.*;

public class Enemy
{
protected float x;
protected int y;
protected int w;
protected int h;
protected Image image;
protected int hitpoints;

Enemy(Image img, int xx, int yy, int ww, int hh, int hp)
{
x = xx;
y = yy;
w = ww;
h = hh;
image = img;
hitpoints = hp;
}

public boolean hit()
{

hitpoints -= 1;
if (hitpoints < 0)
 return true;
else
 return false;
}

public boolean collide(Player player, ImageCanvas imageCanvas)
{
/*FIXME
 int px = player.x;
 int py = player.y;
 int mapx = imageCanvas.x;
 int mapy = imageCanvas.y;
 

 if (player.swordpaint > 0 && (px > x+mapx-2*w) && (px < x+mapx+w)) {
  System.out.println("Collide with sword");
  return true;
 } else {
  return false;
 }*/
  return false;
}
public void addToX(float xx)
{
 x += xx;
// return (x);
}

public void addToY(int yy)
{
 y += yy;
// return (y);
}

public void update()
{
}
void draw(ImageCanvas ic)
{
    ic.drawEnemy(this);
}
void drawEnemy(ImageCanvas ic)
{
    ic.paintEnemy(this);
}

public Image getImage()
{
 return image;
}
public float getX()
{
 return x;
}

public int getY()
{
 return y;
}
};
package games;

public class EnemyVector extends Vector<Enemy>
{
  public EnemyVector(int w) { v = new Enemy[w]; }
  
};
package games;
import java.awt.*;                                                              
import java.awt.event.*;
import java.applet.*;                                                           
                                                                                
public class ImageCanvas extends Component { 
java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
  private MapTileVector mapvec;
  static private
 int x; 
  static private
 int y; 
  private
 int w; 
  private
 int h; 
  Image playerimage;
  int playerx;
  int playery;
  Image enemyimage;
  int enemyx;
  int enemyy;
  static Image bgimage;
  static Image roombgimage;
  String mapfilename;  

  public EnemyVector enemies = new EnemyVector(100);

public ImageCanvas(String filename, int ww, int hh) {  
  x = 0;
  y = 0;
  w = ww;
  h = hh;               
  mapvec = new MapTileVector(filename, ww, hh);
  this.bgimage = toolkit.getImage("./pics/defaultbg1-800x600.png");
  this.roombgimage = toolkit.getImage("./pics/bg1-800x600.png");//FIXME defaultbg
//
//  addEnemy(new Snail(300,250));
//  addEnemy(new Snail(600,250));
//  addEnemy(new Snail(900,250));
}                    


public void addEnemy(Enemy e) {
  enemies.add(e);
}

public void setRoomData(Room r)
{
  //reinit map coords 
  
  r.setRoomData(this);
  //FIXME mapvec = new MapTileVector(mapfilename, w, h);
  //FIXME
  x = 0;
  y = 0;
 
}


  public boolean collideWithPlayer(Player p)
  {
 return mapvec.collide(p.getX(),p.getY(), x,y);
  }

  public boolean collide(Player p)
  {
 return p.collide(this);
 //return mapvec.collide(p.getX(),p.getY(0);
  }

  public void drawEnemy(Enemy e)
  {
 e.drawEnemy(this);
  }
  public void drawPlayer(Player p)
  {
 p.drawPlayer(this);
  }
  public void drawSwordPlayer(Player p)
  {
 p.drawSwordPlayer(this);
  }
                      
  public void paintPlayer(Player p)
  {
 playerimage = p.getImage();
 playerx = p.getX();
 playery = p.getY(); 
  }
  public void paintSwordPlayer(Player p)
  {
 playerimage = p.getSwordImage();
 playerx = p.getX();
 playery = p.getY(); 
  }
  public void paintEnemy(Enemy e)
  {
 enemyimage = e.getImage();
 enemyx = (int)e.getX();
 enemyy = (int)e.getY(); 
  }

  public void paint(Graphics g) {                                               
    //setSize(800,600);                               
 /*for (int j = 0; j < h; j++)
 {
  for (int i = 0; i < w; i++)
  {
         Image img = mapvec.ref(i+j*w).getImage();                                          
   if (img != null) { 
          g.drawImage(img, x+i*16, y+j*16, this);                                           
   }
  }
  //draw bg
   //g.drawImage(img, x+i*16, y+j*16, this)
   }     
*/

 //draw bg & room bg
 System.out.println("*****************x=" + (int)x + " y=" + (int)y + roombgimage);
 //g.drawImage(bgimage, getX(), getY(), this); 
 g.drawImage(roombgimage, x, y, this); 
 //FIXMEif (bgimage != null) { 
 //g.drawImage(roombgimage, getX(), getY(), this); 
 //}
 //draw enemies 
 for (int i = 0; i < 100; i++)
 {
  Enemy e = enemies.vectorRef(i);
  if (e==null)
   continue;
  e.update();
  enemyimage = e.getImage();
  if (enemyimage != null) { 
         g.drawImage(enemyimage, (int)(e.getX()+x), (int)(e.getY()-y), this);
  }
 }
 //draw player
 if (playerimage != null) {
  //System.out.println("foo");   
        g.drawImage(playerimage, playerx, playery, this);
 }
 
}                                                                        

public void addToX(int xx)
{
 System.out.println("x="+x+" y="+y);
 //if (x <= 0 && x > -700)
  x += xx;
  //FIXME
 //else if (x >= 0)
  //x -= 4;
 //else if (x <= -700)
  //x += 4; 
/* if (xx < 0) x += xx;
 else if (x > 0) x -= xx;
 return (x);
*/
}

public void addToY(int yy)
{
 y += yy;
}

public void setX(int xx)
{
 x = xx;
}

public void setY(int yy)
{
 y = yy;
}

public int getX()
{
 return x;
}

public int getY()
{
 return y;
}

}; 
package games;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

public class Main extends Applet
{

static private int DX = 3;
static private int DY = 3;

public final static void main(String[] args)
{
java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
//NOTE final
final Frame f = new Frame("Butterfly");
final ImageCanvas imageCanvas = new ImageCanvas("./mapfile.1", 50,37);

imageCanvas.setSize(800,600);
f.add(imageCanvas);//, BorderLayout.LEFT);
f.pack();
f.setSize(800,600);

final Player player = new Player();

f.addKeyListener(
new KeyListener() 
{
public void keyPressed(KeyEvent e) {                                  
//   System.out.println("foo="+e.getKeyChar());
	
	if (e.getKeyChar() == 'j') {
		imageCanvas.addToX(DX);
		f.show();
	}		
	if (e.getKeyChar() == 'l') {
		imageCanvas.addToX(-DX);
		f.show();
	}		
	if (e.getKeyChar() == 's') {
		player.notifySword();//drawWithSword(imageCanvas);
		f.show();
	}		
/*	if (e.getKeyChar() == 'i') {
		enemies[0].addToY(DY);
		imageCanvas.addToY(DY);
		f.show();
	}		
	if (e.getKeyChar() == 'k') {
		enemies[0].addToY(-DY);
		imageCanvas.addToY(-DY);
		f.show();
	}		
*/
}
public void keyReleased(KeyEvent e) {                                  
//   System.out.print("bar="); 
}
public void keyTyped(KeyEvent e) {                                  
//   System.out.print("baz="); 
}
public void actionPerformed(ActionEvent e) {                                  
//   System.out.println("foo"); 
}
});

f.show();

Room room = new Room1(toolkit.getImage("./pics/bg1-800x600.png"),
					50,37,
					"./mapfile.1");
imageCanvas.setRoomData(room);

int n = 1;
int j = 0;

while (true) 
{
/*	if (!imageCanvas.collide(player)) {
		imageCanvas.addToY(-1);
	}
*/
	//	room.draw(imageCanvas);
	player.draw(imageCanvas);

	for (int i = 0; i< 100; i++)
	{
		Enemy e = imageCanvas.enemies[i];

		if (e ==null)
			continue;
		e.update();
		if (e.collide(player, imageCanvas)) {
			if (e.hit()) imageCanvas.enemies[i] = null;	
		}
		imageCanvas.drawEnemy(e);
		//e.draw(imageCanvas);
	}
	//if (j++ % 1000000 == 0) { f.show(); j = 0; }

	if ((room.changeRoom(imageCanvas)) != null)
	{
		room = room.changeRoom(imageCanvas);
	}

	//f.show();

}

}


};
package games;
import java.awt.*;

public class MapTile
{
protected Image image;
protected int x;
protected int y;
protected int w = 16;
protected int h = 16;

MapTile(Image img, int xx, int yy)
{
image = img;
x = xx;
y = yy;
}

public boolean collide(int px, int py, int mapx, int mapy)
{
	//NOTE if (px > x && px < x + w && py > y && py < y + h)
	if (py > (y*16)-mapy && py < (y*16 - h)-mapy) {
	int yy = py-mapy;
	//System.out.println("py="+yy+" y="+16*y);
		return true;
	} else {
		return false;
	}
}

public Image getImage() 
{ return image; }

public int getW() 
{ return w; }

public int getH() 
{ return h; }

public int getX()
{
	return x;
}

public int getY()
{
	return y;
}


}
package games;
import java.awt.*;
import java.util.Vector;
import java.util.*;
import java.lang.*;
import java.io.*;

public class MapTileVector
{
protected int mapw;
protected int maph;
protected MapTile maptiles[];

MapTileVector(String filename, int MAPWIDTH, int MAPHEIGHT)
{
mapw = MAPWIDTH;
maph = MAPHEIGHT;
maptiles = new MapTile[MAPWIDTH*MAPHEIGHT];
FileReader f = null;
BufferedReader br = null;
try {
f = new FileReader(filename);
br = new BufferedReader(f);
}
catch (FileNotFoundException e)
{}


java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();

for (int j = 0; j < MAPHEIGHT; j++)
{
	for (int i = 0; i < MAPWIDTH; i++)
	{
	
		try {

		int c = f.read();
		if (c == 65) {		
			maptiles[i+j*mapw] = new MapTile(toolkit.getImage("./pics/tilegreenmosaic1-16x16.png"), i, j);
		}
		else {		
			maptiles[i+j*mapw] = new MapTile(toolkit.getImage("./pics/tilegreymosaic1-16x16.png"), i, j);
		}
		}
		catch (EOFException e) {
      		// no problem, end of file here
    		}
    		catch (IOException e) {
    		}
	

	}
	}
}

public boolean collide(int px, int py, int mapx, int mapy)
{
for (int j = 0; j < maph; j++)
{
	for (int i = 0; i < mapw; i++)
	{
		if (maptiles[i+j*mapw].collide(px,py,mapx,mapy)) {
			return true;			
		}
	}
}
return false;
}

public MapTile ref(int idx)
{
	return maptiles[idx];
}

};
package games;

import java.util.*;
import java.awt.*;

public class Player
{
java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
Image image;
Image swordimage;
protected int x;
protected int y;

protected int swordpaint = 0;

Player()
{

x = 100;
y = 220;
image = toolkit.getImage("./pics/player1-72x72.png");
swordimage = toolkit.getImage("./pics/player2-72x72.png");

}

public boolean collide(ImageCanvas ic)
{

 return ic.collideWithPlayer(this);

}
public void notifySword()
{
if (swordpaint == 0) swordpaint++;
if (swordpaint >= 2) swordpaint = 0;
}


void draw(ImageCanvas ic)
{
   if (swordpaint < 2 && swordpaint != 0) { 
 ic.drawSwordPlayer(this);
 swordpaint++;
   } else {
 ic.drawPlayer(this); 
 swordpaint = 0;
   }
}
void drawWithSword(ImageCanvas ic)
{
    ic.drawSwordPlayer(this);
}
void drawPlayer(ImageCanvas ic)
{
    ic.paintPlayer(this);
}
void drawSwordPlayer(ImageCanvas ic)
{
    ic.paintSwordPlayer(this);
}
void update()
{


}
public Image getImage()
{
 return image;
}
public Image getSwordImage()
{
 return swordimage;
}
public int getX()
{
 return x;
}

public int getY()
{
 return y;
}

};
package games;

import java.awt.*;

public class Room1 extends Room
{
static java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
Room1(int ww, int hh, String mapfn)
{
super(toolkit.getImage("./pics/bg1-800x600.png"), 50,37, "./mapfile.1");
//FIXMEsuper.roombgimage = roombgimg;

}
public void setRoomData(ImageCanvas ic)
{
// ic.roombgimage = super.roombgimage;
// ic.w = w;
// ic.h = h;
// ic.mapfilename = mapfilename;
// ic.enemies = super.enemies; 
  ic.addEnemy(new Snail(300,250));
  ic.addEnemy(new Snail(600,250));
  ic.addEnemy(new Snail(900,250));
}

public Room changeRoom(ImageCanvas ic)
{
 if (ic.getX() < -600) {
 System.out.println("ic.getX="+ic.getX());
  Room room = new Room2(50,37,
     "./mapfile.1");
  ic.setRoomData(room);
  return room;  
 }
 return null;
}
};

package games;

import java.awt.*;

public class Room2 extends Room
{
static java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
Room2( int ww, int hh, String mapfn)
{
  super(toolkit.getImage("./pics/bg2-2400x600.png"), 50,37, "./mapfile.1");
  
//  addEnemy(new Snail(300,250));
//  addEnemy(new Snail(600,250));
//  addEnemy(new Snail(900,250));
  
}

//public void setRoomData(ImageCanvas ic)
//{
// ic.roombgimage = roombgimage;
// ic.w = w;
// ic.h = h;
// ic.mapfilename = mapfilename;
// ic.enemies = super.enemies; 
//}
public Room changeRoom(ImageCanvas ic)
{
 if (ic.getX() > 0) {
 System.out.println("ic.getX="+ic.getX());
  Room room = new Room1(//toolkit.getImage("./pics/bg1-800x600.png"),
     50,37,
     "./mapfile.1");
  ic.setRoomData(room);
  return room;  
 }
 return null;
}
};


package games;

import java.awt.*;
import java.lang.*;
//import java.util.*;

public class Room
{

private Image roombgimage;
private int w;
private int h;
private String mapfilename;
//private static Enemy enemies[] = new Enemy[100];
  //private static java.util.Vector<Enemy> enemies = new java.util.Vector();
Room(Image bgimg, int ww, int hh, String mapfn)
{
roombgimage = bgimg;
w = ww;
h= hh;
mapfilename = mapfn;

}

public void setRoomData(ImageCanvas ic)
{
  //FIXME
 ic.roombgimage = roombgimage;
 //ic.w = w;
 //ic.h = h;
 ic.mapfilename = mapfilename;
//// ic.x = 0;
// ic.y = 0;
}

public Room changeRoom(ImageCanvas ic)
{
/* if (ic.getX() % 600 == 0) {
  
 }
*/

 return null;

}
};
package games;

import java.awt.*;
import java.awt.event.*;

public class Snail extends Enemy
{
java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
Snail(int xx, int yy)
{
super(null,xx,yy, 20, 36,36);
super.image = toolkit.getImage("./pics/snail1-36x36.png");
}
public boolean hit()
{

hitpoints -= 1;
if (hitpoints < 0)
	return true;
else
	return false;
}

void drawEnemy(ImageCanvas ic)
{
    ic.paintEnemy(this);
}
public void update()
{
x -=0.000004;
}
};
package games;

import java.util.*;

public class StateImageLibrary
{

private int index;
private int max;

public void addImage(String filename)
{


} 

};
package games;

public class Vector<T>
{
  protected T v[];
  private int index = 0;
  
  public T vectorRef(int idx)
  {
    return v[idx];
  }

  
  public void vectorSet(int idx, T e)
  {
    v[idx] = e;
  }
  
  public void add(T e)
  {
    v[index++] = e;
  }
  
};
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
A00000000000000000000000000000000000000000000000A
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

\end{verbatim}
\end{mylisting}


\section{\large Conclusion}


\bibliographystyle{plain}
\bibliography{refs} % refs.bib

\end{document}


